import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

import path from "path";
export default defineConfig({
  plugins: [vue()],
  esbuild: {
    target: "esnext", // 与 tsconfig.json 中的 module 选项一致
  },
  assetsInclude: ["**/*.png"],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
      "@views": path.resolve(__dirname, "src/views"),
    },
  },
   build: {
    outDir: 'dist',
  },
  server: {
    proxy: {
      "/api": {
        target: "http://www.manfenbx.com/api",
        // target: "http://www.manfen.org/api",
        // target: "http://123.57.81.131:8080/api",
        // target: "http://192.168.124.13/api",
        changeOrigin: true,
        rewrite: (path) => {
          const newPath = path.replace(/^\/api/, "");
          return newPath;
        },
        // 添加以下配置
        configure: (proxy, options) => {
          proxy.on("proxyReq", (proxyReq, req, res) => {
            // 打印实际请求的完整地址
            const target = proxyReq.getHeader("host");
            const path = proxyReq.path;
            const fullUrl = `http://${target}${path}`;
          });
        },
      },
      // 新增图片代理Public
      "/Uploads": {
        target: "http://manfenbeikao.com",
        changeOrigin: true,
        // rewrite: (path) => path.replace(/^\/manfenbeikao/, ""),
      },
      // 新增图片代理Public
      "/www": {
        // target: "http://192.168.118.244/",
        target: "http://123.57.81.131:8081/",
        changeOrigin: true,
      },
      "/Public": {
        target: "http://manfenbeikao.com",
        changeOrigin: true,
        // rewrite: (path) => path.replace(/^\/manfenbeikao/, ""),
      },

      "pdf/": {
        target: "https://manfenbeikao.com/",
        changeOrigin: true,
        // rewrite: (path) => path.replace(/^\/manfenbeikao/, ""),
      },
      "/aichat": {
        // target: "http://192.168.1.194/",
        target: "http://123.57.81.131:8081/",
        changeOrigin: true,
        // rewrite: (path) => path.replace(/^\/manfenbeikao/, ""),
      },
    },
  },
});
